<?php
/**
 * 个人会员中心   订单类
 * @author      HJC <hujianchuang@haowj.com>
 * @update      2014.07.01
 * @since       Version 1.0
 * 
 */
class OrderAction extends BaseAction 
{
    public function index()
    {
        $user_id = $this->userInfo['id'];
        $addSql = " and flag=".C('PACKCLASSTYPE'); //只计算 小包课得订单
        $orders = D('Order')->where("user_id=".$user_id.$addSql)->order("id desc")->select();
        if($orders)
        {
            foreach ($orders as $k=>$v)
            {
                $arr = explode(',', $v['course_id']);
                foreach ($arr as $key=>$val)
                {
                    $orders[$k]['course_info'][$key] = D('new_course')->where("id=".$val)->find();
                }
            }
        }
        $seo['title'] = '我的订单_好外教网'; 
       
        $this->assign('seo',$seo);
        
        $this->assign('orders',$orders);
        $this->display();
    }
    //删除订单
    function delOrder()
    {
        $user_id = $this->userInfo['id'];
        if(!IS_AJAX) $this->ajaxReturn('','非法请求！',0); 
        $oid  = $this->_post('sid');
        if(!$user_id||!$oid)  $this->ajaxReturn('0','非法请求！',0);
        $data['flag'] = 0;
        if(D('Order')->where("user_id=".$user_id." and id=".$oid)->data($data)->save())  $this->ajaxReturn('0','删除成功！',1);
        else  $this->ajaxReturn('0','删除失败！',0);
        
    }
}